package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.LoginMapper;
import com.itheima.pojo.Member;
import com.itheima.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    //验证码登录
    //根据手机号查询当前用户
    @Override
    public Member findByPhone(String telephone) {
        LambdaQueryWrapper<Member> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Member::getPhoneNumber,telephone);
        Member member = loginMapper.selectOne(wrapper);
        return member;
    }
    //把第一次登录的新用户存到用户表中
    @Override
    public Member add(String telephone) {
        Member member = new Member();
        member.setPhoneNumber(telephone);
        loginMapper.insert(member);

        return member;
    }

}
